<#assign basePath=request.contextPath />
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>用户列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link href="${basePath}/js/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
    <script src="${basePath}/js/jquery1.8.3.min.js"></script>
    <script src="${basePath}/js/layer/layer.js"></script>
    <script src="${basePath}/js/bootstrap/3.3.5/js/bootstrap.min.js"></script>
    <script src="${basePath}/js/shiro.demo.js"></script>
</head>
<body>
<div class="container-fluid">
    <div class="row">
        <div class="col-md-12">
        <#--<h3>用户列表</h3>-->
        <#--<hr>-->
            <form style="margin-top: 1.5em" method="post" action="${basePath}/user/userList" id="formId"
                  class="form-inline">
                <div clss="well">
                    <div class="form-group">
                        <input type="text" class="form-control" style="width: 300px;" value="${user.nickname?default('')}"
                               name="nickname" id="nickname" placeholder="输入昵称 / 帐号">
                    </div>
                    <span class=""> <#--pull-right -->
				         	<button type="submit" class="btn btn-primary">查询</button>
				         		<button type="button" id="deleteAll" class="btn  btn-danger">删除</button>
				         </span>
                </div>

                <hr>
                <table class="table table-bordered">
                    <tr>
                        <th><input type="checkbox" id="checkAll"/></th>
                        <th>昵称</th>
                        <th>Email/帐号</th>
                        <th>登录状态</th>
                        <th>创建时间</th>
                        <th>最后登录时间</th>
                        <th>操作</th>
                    </tr>


                    <#if page?exists && page.result?size gt 0 >
                        <#list page.result as it>
                        <tr>
                            <td><input value="${it.id}" check='box' type="checkbox"/></td>
                            <td>${it.nickname?default('未设置')}</td>
                            <td>${it.email?default('未设置')}</td>
                            <td>${(it.status==1)?string('有效','禁止')}</td>
                            <td>${it.createTime?string('yyyy-MM-dd HH:mm')}</td>
                            <td>${it.lastLoginTime?string('yyyy-MM-dd HH:mm')}</td>

                            <td>
                                ${(it.status==1)?string('<i class="glyphicon glyphicon-eye-close"></i>&nbsp;','<i class="glyphicon glyphicon-eye-open"></i>&nbsp;')}
                                <a href="javascript:forbidUserById(${(it.status==1)?string(0,1)},${it.id})">
                                    ${(it.status==1)?string('禁止登录','激活登录')}
                                </a>
                                <a href="javascript:_delete([${it.id}]);">删除</a>
                            </td>
                        </tr>
                        </#list>
                    </#if>
                </table>
                <#if page?exists>
                <div class="pagination pull-right">
                    ${page.pageHtml}
                </div>
                </#if>
            </form>
        </div>
    </div>
</div>
</body>
<script>
    so.init(function () {
        //初始化全选。
        so.checkBoxInit('#checkAll', '[check=box]');
        //全选
        so.id('deleteAll').on('click', function () {
            var checkeds = $('[check=box]:checked');
            if (!checkeds.length) {
                return layer.msg('请选择要删除的选项。', so.default), !0;
            }
            var array = [];
            checkeds.each(function () {
                array.push(this.value);
            });
            return _delete(array);
        });
    });

    //根据ID数组，删除
    function _delete(ids) {
        var index = layer.confirm("确定这" + ids.length + "个用户？", function () {
            var load = layer.load();
            $.post('${basePath}/user/deleteUserById', {ids: ids.join(',')}, function (result) {
                layer.close(load);
                if (result && result.status != 200) {
                    return layer.msg(result.message, so.default), !0;
                } else {
                    layer.msg('删除成功');
                    setTimeout(function () {
                        $('#formId').submit();
                    }, 1000);
                }
            }, 'json');
            layer.close(index);
        });
    }
</script>
</html>